package com.yugao.fintech.antelope.base.config.model.mq;

import com.yugao.fintech.antelope.base.config.model.ActionTypeEnum;
import com.yugao.fintech.antelope.base.model.constants.ConfigCons;
import com.yugao.fintech.antelope.base.model.module.mq.AbstractMQ;
import com.yugao.fintech.antelope.base.model.module.mq.BaseMqPayload;
import lombok.*;

/**
 * 消息推送队列
 */
public class RefreshConfigMQ extends AbstractMQ {
    public static final String KEY = "";
    public static final String EXCHANGE = "dynamic_config_refresh";

    public static final String REFRESH_ALL = "*";

    public RefreshConfigMQ(MsgPayload msgPayload) {
        super(msgPayload);
    }

    @Data
    @Builder
    @EqualsAndHashCode(callSuper = true)
    @AllArgsConstructor
    @NoArgsConstructor
    public static class MsgPayload extends BaseMqPayload {
        /**
         * 数据键值
         *
         * @see ConfigCons
         */
        private String dataKey;
        /**
         * 可选
         */
        private String dataHashKey;

        private String dataValue;
        /**
         * 如果为✳则刷新全部服务
         */
        private String serviceId;

        /**
         * 配置类型
         *
         * @see ConfigType
         */
        private String configType;

        /**
         * 动作类型
         */
        private ActionTypeEnum actionType;

        public String toMessage() {
            return new RefreshConfigMQ(this).toMessage();
        }
    }

    public static MsgPayload.MsgPayloadBuilder builder() {
        MsgPayload.MsgPayloadBuilder builder = MsgPayload.builder();
        builder.serviceId(REFRESH_ALL);
        return builder;
    }
}
